package logic

import (
	"context"
	"time"
	"we-chat/cache"
	"we-chat/models"

	"we-chat/userrpc/internal/svc"
	"we-chat/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *userrpc.UserListRequest) (*userrpc.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var userLists []models.User
	var users []*userrpc.List
	for _, data := range userLists {
		list := userrpc.List{
			Name:    data.Name,
			Address: data.Address,
			Title:   data.Title,
			Context: data.Context,
		}
		users = append(users, &list)
	}
	cache.Rdb.Set(l.ctx, "list", users, time.Minute*5)
	return &userrpc.UserListResponse{
		List: users,
	}, nil
}
